package com.yunyike.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yunyike.constants.CartConstants;
import com.yunyike.dto.SettlementDTO;
import com.yunyike.model.Payment;
import com.yunyike.redis.JedisManager;
import com.yunyike.service.IPaymentService;

/**
 * @author zhengqiang.shi
 * 2015年11月26日 下午10:17:59
 */
@Service("paymentServiceImpl")
public class PaymentServiceImpl implements IPaymentService {

	private static Logger log = LoggerFactory.getLogger(PaymentServiceImpl.class);
	
	/**
	 * 选择支付方式
	 */
	public void choosePaymentType(Payment payment, String sessionId) {
		
		log.info("choose PaymentType...");
		
		// settlement redis key
		log.info("----->> generator settlement key...");
		String settlementKey = CartConstants.settlementKey(sessionId);
		log.info("settlement key:"+settlementKey);
		
		// 获取当前结算信息
		log.info("get settlement data from redis...");
		try {
			SettlementDTO settlementDTO = (SettlementDTO)JedisManager.getObject(settlementKey);
			settlementDTO.setPayment(payment);
			JedisManager.setObject(settlementKey, CartConstants.SETTLEMENT_OUT_TIME, settlementDTO);
		} catch (Exception e) {
			log.error("choosePaymentType has error,message:"+e.getMessage(),e);
		}
		
		log.info("choose payment type end.");
	}
}
